/**
 * 数据模块
 */
import types from "../types";

import {PERMISSION_CHECK, httpPost} from "../../api/api";

const state = new Map();

// getters
const getters = {
};

// actions
const actions = {
  permissionCheck ({ commit, state }, payload) {
    let url = payload.url;
    if (state.has(url)){
      return state.get(url);
    }else {
      return httpPost(PERMISSION_CHECK, payload).then(res => {
        if (res){
          commit(types.ADD_PERMISSION_URL, {url:url, result: res});
          return res;
        }
      })
    }
  }
};

// mutations
const mutations = {
  [types.ADD_PERMISSION_URL] (state, obj) {
    state.set(obj.url, obj.result);
  }
};

export default {
  state,
  getters,
  actions,
  mutations
}
